<?php 

	header('Content-type:text/html;charset=utf-8');
	class ShopGoodsListController extends CommonController{

		public $model;

		public function __init(){
			parent:: __init();
			$this->model=K('Shop_goods_list');
		}

		public function index(){
			$gid = Q('get.gid',0,'intval');
			$where = array('shop_goods_gid'=>$gid,'class'=>1,'taname'=>'颜色');
			// p($gid);die;
			$color = M()->join('__shop_goods_attr__ gat JOIN __shop_type_attr__ tat ON gat.shop_type_attr_taid=tat.taid')->where($where)->all();
			// p($color);
			$this->assign('color',$color);

			$where = array('shop_goods_gid'=>$gid,'class'=>1,'taname'=>'尺寸');
			$size =  M()->join('__shop_goods_attr__ gat JOIN __shop_type_attr__ tat ON gat.shop_type_attr_taid=tat.taid')->where($where)->all();
			// p($size);
			$this->assign('size',$size);

			//从goodlist表中调数据
			$gid= Q('get.gid',0,'intval');
			$goodsData = $this->model->where("shop_goods_gid={$gid}")->all();
			foreach ($goodsData as $k => $v) {
				//将改成数组后的combine，附回$goodsData[$k]中的combine中
				$goodsData[$k]['combine'] = explode(',', $v['combine']);
			}
			// p($goodsData);
			$this->assign('goodsData',$goodsData);

			$this->display();
		}

		public function add(){

			$a = $_POST;

			$temp = array(
				'color' =>$a['color'],
				'size'  =>$a['size'],
				);

			$combine = implode(',', $temp);

			$goodsListData = array(
				'combine'   =>$combine,
				'inventery' =>$a['inventery'],
				'number'    =>$a['number'],
				'shop_goods_gid'=>$a['gid'],

				);
			$this->model->add($goodsListData);

			$this->ajax($goodsListData,'json');

		}

		public function edit(){
			//选择数据的调取
			$gid = Q('get.gid',0,'intval');
			$where = array('shop_goods_gid'=>$gid,'class'=>1,'taname'=>'颜色');
			// p($gid);die;
			$color = M()->join('__shop_goods_attr__ gat JOIN __shop_type_attr__ tat ON gat.shop_type_attr_taid=tat.taid')->where($where)->all();
			// p($color);
			$this->assign('color',$color);

			$where = array('shop_goods_gid'=>$gid,'class'=>1,'taname'=>'尺码');
			$size =  M()->join('__shop_goods_attr__ gat JOIN __shop_type_attr__ tat ON gat.shop_type_attr_taid=tat.taid')->where($where)->all();
			$this->assign('size',$size);
			//调要修改的老数据
			$glid = Q('get.glid',0,'intval');
			$goodsData = $this->model->where("glid={$glid}")->find();
			$goodsData['combine']=explode(',', $goodsData['combine']);
			// p($goodsData);
			$this->assign('goodsData',$goodsData);
			//将修改的内容传到数据库
			if (IS_POST) {
				// p($_POST);
				$glid = Q('post.glid',0,'intval');
				// p($glid);die;
				$this->model->where("glid={$glid}")->update();
				//如何跳转到首页？？？
				$this->success('修改成功');

			}
			$this->display();
		}

		public function del(){

			$glid = Q('get.glid',0,'intval');
			
			$this->model->del($glid);
			$this->success('删除货品成功');
		}
	}














 ?>